package com.authine.cloudpivot.web.api.common;

//import org.apache.axis.client.Call;
//import org.apache.axis.client.Service;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.json.XML;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.xml.namespace.QName;
//import javax.xml.rpc.ParameterMode;
//import javax.xml.rpc.ServiceException;
//import javax.xml.rpc.encoding.XMLType;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;

/**
 * pancw
 */
public class WebServiceUtil {

    private static  Logger logger = LoggerFactory.getLogger(WebServiceUtil.class);

    public static String send_url = "http://192.168.31.250:9080";

    public final static String RECORD_FROM_WEB = "https://bpmtest.babycare.com/";

//    /**
//      * @methodName getService
//      * @param methodName 方法名
//      * @param data 参数字符串集合
//      * @return java.lang.String 响应的结果
//      **/
//    public static String getService(String methodName,String data) throws ServiceException, MalformedURLException, RemoteException {
//        logger.info("methodName: "+methodName + ", data: "+ data);
//        Service service = new Service();
//        Call call = (Call) service.createCall();
//        URL endpoint = new URL(send_url+"/service/XChangeServlet");
//        call.setTargetEndpointAddress(endpoint);
//        call.setOperation(new QName(RECORD_FROM_WEB), methodName);
//        call.addParameter(new QName("data"), XMLType.SOAP_STRING,ParameterMode.IN);
//        call.setReturnType(XMLType.SOAP_STRING);
//        logger.info("call: "+call.toString());
//        String ret = (String)call.invoke(new Object[]{ });
//        logger.info("webservice return : " + ret);
//        ret = ret.replaceAll("'","\"");
//        return ret;
//    }
//
//
//    public static String getServiceWithServiceName(String serviceName,String methodName,String data) throws ServiceException, MalformedURLException, RemoteException {
//        logger.info("methodName: "+methodName + ", data: "+ data);
//        Service service = new Service();
//        Call call = (Call) service.createCall();
//        URL endpoint = new URL(send_url+serviceName);
//        call.setTargetEndpointAddress(endpoint);
//        call.setOperation(new QName(RECORD_FROM_WEB), methodName);
//        call.addParameter(new QName("parameters"), XMLType.SOAP_STRING,ParameterMode.IN);
//        call.setReturnType(XMLType.SOAP_STRING);
//        logger.info("call: "+call.toString());
//        String ret = (String)call.invoke(new Object[]{data});
//        logger.info("webservice return : " + ret);
//        ret = ret.replaceAll("'","\"");
//        return ret;
//    }
//
//    /**
//     * NCC 请求他调用
//     * @param paramXml
//     * @param postUrl
//     * @return
//     * @throws IOException
//     */
//    public static String doSapWebService(String paramXml, String postUrl) throws IOException {
//        String returnXmlStr = "";
//        CloseableHttpClient client = HttpClients.createDefault();
//        HttpPost post = new HttpPost(postUrl);
//        StringEntity myEntity = new StringEntity(paramXml, "UTF-8");
//        // 设置请求体
//        post.setEntity(myEntity);
//        post.setHeader("content-type","text/xml;charset=utf-8");
//        CloseableHttpResponse response = null;
//        response = client.execute(post);
//        HttpEntity entity = response.getEntity();
//        returnXmlStr = EntityUtils.toString(entity, "UTF-8");
//
//        if (response != null){
//            response.close();
//        }
//        if (client != null){
//            client.close();
//        }
//        if (response.getStatusLine().getStatusCode() == 200) {
//            return XML.toJSONObject(returnXmlStr).toString();
//        }
//        return returnXmlStr;
//    }
}
